<template>
  <div class="container">
    <div class="news-ad">
      <image :src="banner" />
    </div>
    <Line :text="ftitle"> </Line>

    <NewsList :list="newsList"> </NewsList>
    <div class="end-flag end-flag-loding" v-show="isLoading === true">正在加载中...</div>
    <div class="end-flag end-flag-isnext" v-show="isNext === false">已加载全部</div>
    <Contact> </Contact>
  </div>

</template>
<script>
const wxapp = getApp()
import Line from '@/components/Line'
import Contact from '@/components/contact'
import NewsList from '@/components/News/NewsList'
  export default {
    data(){
      return {
        isLoading : false,
        isNext: true,
        newsList : [],
        page: 1,
        banner: '../../static/news-ad.png',
        ftitle: '大家都在聊'
      }
    },
    components:{
      Line,
      NewsList,
      Contact
    },
    onReachBottom(){
      console.log('首页滑动到底部');
      if(this.isLoading == true || this.isNext != true){
        return;
      }
      this.isLoading = true;
      this.page += 1
      this.getList()

    },
    onShow() {
      //this.getList()
      this.getList()
      this.getCate()
    },
    methods: {
      getList() {
        wx.showLoading({
  title: '加载中',
})
        let that = this
        wx.request({
          url: wxapp.globalData.ROOT_URL, //仅为示例，并非真实的接口地址
          data: {
             siteid: '4' ,
             service: 'App.Hong.Index',
             page: that.page,
             table: '4_news',
             ftable: '4_news_category'
          },
          success: function(res) {
            wx.hideLoading()
            that.isLoading = false
            if(res.data.data.result == 0) {
              wx.showToast({
                title: '没有了',
                icon: 'success',
                duration: 2000
              })
              that.isNext = false
            }else {
              let list = res.data.data.result
              if(that.page >1) {
                let newsList = that.newsList
                for(let i in list) {
                  newsList.push(list[i])
                }
                that.newsList = jobList
              }else {
                that.newsList = list
              }
            }
            console.log(that.newsList)

          }
        })
      },
      getCate() {
        let that = this
        wx.request({
          url: wxapp.globalData.ROOT_URL, //仅为示例，并非真实的接口地址
          data: {
             service: 'App.Hong.GetCategoryInfo',
             table: '4_share_category',
             id: 1
          },
          header: {
              'content-type': 'application/json' // 默认值
          },
          success: function(res) {
            that.navlist = res.data.data.result
            that.banner = that.navlist['thumb']
            that.ftitle = that.navlist['dirname']
          }
        })
      }
    }
  }
</script>
<style scoped>
.news-ad{
  height: 310rpx;
}
.news-ad image{
  width: 100%;
  height: 310rpx;
}

</style>
